﻿using HarmonyLib;
using MarriageFertility.Helpers;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;

namespace MarriageFertility.Patches
{
    public static class CharacterObjectPath
    {
        [HarmonyPatch(typeof(CharacterObject), "UpdatePlayerCharacterBodyProperties")]
        private static class CharacterObjectPatch
        {
            private static void Postfix(CharacterObject __instance, BodyProperties properties, int race, bool isFemale)
            {
                // 直接判断是否是非玩家角色并且是英雄角色
                if (__instance.IsPlayerCharacter || !__instance.IsHero) return;

                Hero heroObject = __instance.HeroObject;  // 获取 HeroObject 实例

                // 设置角色种族和体型属性
                __instance.Race = race;
                ReflectUtils.ReflectPropertyAndSetValue("StaticBodyProperties", properties.StaticProperties, heroObject);
                heroObject.Weight = properties.Weight;
                heroObject.Build = properties.Build;
                heroObject.UpdatePlayerGender(isFemale);
            }
        }
    }
}